package com.shxc.smarttrade.quotation.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.shxc.smarttrade.R;

import java.util.List;

/**
 * 行情 - 自选
 */
public class QuotationChoosePagerAdapter extends PagerAdapter {
    private LayoutInflater inflater;
    private Context c;
    private QuotatonChooseBottomAdapter adapter0;//0 外汇；
    private QuotatonChooseBottomAdapter adapter1;//1 指数；
    private QuotatonChooseBottomAdapter adapter2;//2 贵金属；
    private QuotatonChooseBottomAdapter adapter3;//3 能源；
    private List<String> tabTitleList;

    public QuotationChoosePagerAdapter(LayoutInflater inflater, Context c,
                                       List<String> tabTitleList,
                                       QuotatonChooseBottomAdapter adapter0,
                                       QuotatonChooseBottomAdapter adapter1,
                                       QuotatonChooseBottomAdapter adapter2,
                                       QuotatonChooseBottomAdapter adapter3) {

        this.c = c;
        this.inflater = inflater;
        this.tabTitleList = tabTitleList;
        this.adapter0 = adapter0;
        this.adapter1 = adapter1;
        this.adapter2 = adapter2;
        this.adapter3 = adapter3;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0.equals(arg1);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View convertView = inflater.inflate(R.layout.quotaton_recycler, null);

        RecyclerView recyclerview = convertView.findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(new GridLayoutManager(c,3));

        switch (position) {
            case 0:
                //外汇
                recyclerview.setAdapter(adapter0);
                break;
            case 1:
                //贵金属
                recyclerview.setAdapter(adapter2);
                break;
            case 2:
                //能源
                recyclerview.setAdapter(adapter3);
                break;
            case 3:
                //指数
                recyclerview.setAdapter(adapter1);
                break;
        }
        ((ViewPager) container).addView(convertView);
        return convertView;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return tabTitleList.get(position);
    }
}
